package com.ktgj.pay.api.factory;

import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.pay.api.RemotePayService;
import com.ktgj.pay.api.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 *  * 会员服务降级处理
 * @author ruoyi
 */
@Component
public class RemoteWeChatPayFallbackFactory implements FallbackFactory<RemotePayService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteWeChatPayFallbackFactory.class);

    @Override
    public RemotePayService create(Throwable cause) {
        log.error("会员服务调用失败:{}", cause.getMessage());
        return new RemotePayService() {

            @Override
            public R<Map> createNative(Long orderId, String body, String out_trade_no, BigDecimal totalFee) {
                return R.fail("获取微信支付扫描二维码失败" + cause.getMessage());
            }

            @Override
            public R<Map> getWechatJSAPIPayParam(String openId, BigDecimal money, String orderNumber, String notifyUrl) {
                return R.fail("获取微信支付参数(JSAPI)失败" + cause.getMessage());
            }

            @Override
            public AjaxResult refundWechat(String orderNumber, String refundNumber, String notifyUrl, BigDecimal refundMoney, BigDecimal totalMoney)
            {
                log.error("微信退款异常！");
                return null;
            }

            @Override
            public List<PayTypeApi> queryPayType(String businessType) {
                log.error("获取支付类型调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi CreditSale(BankPayInfoApi bankPayInfo)
            {
                log.error("信用卡支付调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi VerifySale(Map<String, Object> map) {
                log.error("验证码确认消费调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi VerifyCodeReceive(String jsjOrderId) {
                log.error("订单验证码获取调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi DebitSale(BankPayInfoApi bankPayInfo) {
                log.error("借记卡支付调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi bankDebitRefund(Map<String, String> map)
            {
                log.error("借记卡退款调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public YeeBaoResultApi bankCreditRefund(Map<String, String> map)
            {
                log.error("信用卡退款调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public UnionPayQRCodeResponseApi getQRCode(Map<String, String> map)
            {
                log.error("获取银联二维码调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public UnionPayQRCodeResponseApi qrCodeRefund(Map<String, String> map)
            {
                log.error("银联二维码退款调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public AjaxResult queryQRCodeOrder(Map<String, String> map)
            {
                log.error("查询银联二维码订单调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public boolean isPaySuccessful(Map<String, String> resultMap) {
                log.error("验证是否通过调用失败:{}", cause.getMessage());
                return Boolean.parseBoolean(null);
            }

            @Override
            public String voicePay(Map<String, Object> map) {
                log.error("语音支付调用失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public List<InvoiceInvoiceOrderApi> getListByCustomerId(String jsjid) {
                log.error("会员发票订单获取失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public String postAliPayParam(Map<String, Object> map) {
                log.error("支付宝支付调用失败失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public String postUnionPayParam(Map<String, Object> map) {
                log.error("银联支付调用失败失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public AjaxResult add(InvoiceInvoiceOrder invoiceInvoiceOrder) {
                log.error("新增发票订单失败:{}", cause.getMessage());
                return null;
            }

            @Override
            public int queryEmailState(Long orderId) {
                log.error("查询发票配送状态失败:{}", cause.getMessage());
                return 0;
            }

//            @Override
//            public List<PayTypeApi> queryPayType(Map<String, Object> map) {
//                log.error("获取支付类型调用失败:{}", cause.getMessage());
//                return null;
//            }
        };
    }
}
